package com.example.demo.dao;

import com.example.demo.entity.Address;
import com.example.demo.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface UserDAO {
    public User selectUserByPhoneAndPassword(@Param("phone") String phone, @Param("password") String password);

    public void insertnewUser(@Param("username") String userName, @Param("password") String password, @Param("phone") String phone);

    public User findByPhone(@Param("phone") String phone);

    public User findById(@Param("userid") int userid);

    public User findByToken(@Param("token") String token);

    public void updateById(@Param("userid") int userid,@Param("username") String userName, @Param("password") String password);

    public void updateVIP(@Param("userid") int userid,@Param("IDCard") String IDCard, @Param("realname") String realname);

    public void bindUser(@Param("userid") int userid,@Param("token") String token);

    public void addMoney(@Param("userid") int userid,@Param("point") double point);

    public List<Address> getAddress(@Param("userid") int userid);

    public void insertnewAddress(Address address);

    public void updateAddress(@Param("address") String address, @Param("phone") String phone, @Param("name") String name, @Param("addressid") int addressid, @Param("region") String region);

    public void deleteAddress(@Param("addressid") int addressid);

    public Address findAddressById(@Param("addressid") int addressid);


    List<User> getUserList(int star,@Param("searchMsg") String searchMsg);
    int getUserListTotal(@Param("searchMsg")String searchMsg);

    void deleteUserById(@Param("id") int id);

    @Update("update user set username=#{username},password=#{password},phone = #{phone}," +
            "address = #{address},point=#{point} where userid = #{userid}")
    void editUser(User user);
}
